//! mpec寄存器0x341
//! 当处理器陷入M模式时，中断或遇到异常的指令的虚拟地址会写入mepc寄存器中。

use core::arch::asm;

#[inline(always)]
unsafe fn _read() -> usize {
    let r: usize;
    unsafe {
        asm!(
            "csrrs {0}, 0x341, zero",
            out(reg)r
        );
    }
    r
}

#[inline]
pub fn read() -> usize {
    unsafe { _read() }
}

#[inline(always)]
unsafe fn _write(bits: usize) {
    unsafe {
        asm!("csrrw zero, 0x341, {0}", in(reg)bits);
    }
}

#[inline]
pub fn write(bits: usize) {
    unsafe {
        _write(bits);
    }
}
